/**
 * 房间数据
 * @constructor
 */

var User = require("user");

var RoomData = function (mapai, mode, rounds, rid) {
    this.mapai = mapai;                 //马牌
    this.mode = mode;                   //模式
    this.rounds = rounds;               //回合数
    this.rid = rid;                     //房间ID
    
    this.users = [];                    //用户数组
};

//获得马牌
RoomData.prototype.getMapai = function () {
    return this.mapai;
};

//设置当前房间马牌
RoomData.prototype.setMapai = function (value) {
    this.mapai = value;
};

//获得当前房间模式
RoomData.prototype.getMode = function () {
    return this.mode;
};

//设置模式
RoomData.prototype.setMode = function (value) {
    this.mode = value;
};

//获得当前房间总局数
RoomData.prototype.getRounds = function () {
    return this.rounds;
};

//设置总局数
RoomData.prototype.setRounds = function (value) {
    this.rounds = value;
};

//获得当前房间房间号
RoomData.prototype.getRid = function () {
    return this.rid;
};

//设置房间号
RoomData.prototype.setRid = function (value) {
    this.rid = value;
};

//获得房间玩家数组
RoomData.prototype.getUsers = function () {
    return this.users;
};

//添加玩家数据
RoomData.prototype.addUser = function (uid) {
    for (let i = 0; i < this.users.length; i++) {
        if (this.users[i].uid == uid) {
            return;
        }
    }
    var newuser = new User(uid);
    this.users.push(newuser);
};

//删除玩家数据
RoomData.prototype.removeUser = function (uid) {
    for (let i = 0; i < this.users.length; i++) {
        if (this.users[i].uid == uid) {
            this.users.splice(i, 1);
        }
    }
};

module.exports = RoomData;